package com.yinhe.music.yhmusic.login.validcode;

import android.content.Intent;
import android.text.TextUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.base.BaseModel;
import com.yinhe.music.yhmusic.base.BasePresenter;
import com.yinhe.music.yhmusic.base.BaseServiceActivity;
import com.yinhe.music.yhmusic.model.ValidCodeInfo;

/**
 * Created by hasee on 2017/3/24.
 */

public class PhoneNumberActivity extends BaseServiceActivity implements ValidCodeContract.IValidCodeView {

    EditText phone;

    String number;

    ValidCodePresenter mPresenter;

    @Override
    public void initView() {
        setToolbar("重设密码");
        Button next = findViewById(R.id.next);
        phone = findViewById(R.id.phone);
        phone.setFocusable(true);
        phone.requestFocus();
        phone.setInputType(EditorInfo.TYPE_CLASS_PHONE);

        next.setOnClickListener(view -> {
            number = phone.getText().toString().trim();
            if (TextUtils.isEmpty(number)) {
                Toast.makeText(PhoneNumberActivity.this, "请输入手机号码", Toast.LENGTH_SHORT).show();
                return;
            }
            mPresenter.getValidCode(number);
        });
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_phone;
    }

    @Override
    public BasePresenter getPresenter() {
        return mPresenter;
    }

    @Override
    public void initPresenter() {
        mPresenter = new ValidCodePresenter();
        mPresenter.attachModelView(new BaseModel(), this);
    }

    @Override
    public void startNext(ValidCodeInfo info) {

    }

    @Override
    public void getCodeUI() {
        Intent intent = new Intent(PhoneNumberActivity.this, CheckCodeActivity.class);
        intent.putExtra("phone", number);
        intent.putExtra("type", 0);
        startActivity(intent);
    }
}
